﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using TheOutfield.UmbExt.UniversalMediaPicker.Extensions;
using DropNet.Models;
using DropNet;

namespace TheOutfield.UmbExt.UniversalMediaPicker.Providers.Dropbox
{
    public class DropboxService
    {
        private DropboxConfig _config;
        private DropNetClient _client;

        public DropboxService(string config)
        {
            _config = config.DeserializeJsonTo<DropboxConfig>();
            _client = GetDropNetClient();
        }

        public DropboxConfig Config
        {
            get { return _config; }
        }

        public List<MetaData> GetMetaDataList(string path)
        {
            var md = _client.GetMetaData(path);
            return md.Contents;
        }

        public MetaData GetMetaDataItem(string path)
        {
            return _client.GetMetaData(path);
        }

        public byte[] GetFile(string path)
        {
            return _client.GetFile(path);
        }

        private DropNetClient GetDropNetClient()
        {
            return new DropNetClient(Config.ApiKey, Config.ApiSecret, Config.AuthToken, Config.AuthSecret);
        }
    }
}